package com.me.study.javaCore.rmi;

import com.me.study.javaCore.rmi.OrderService;
import com.me.study.javaCore.rmi.User;
import java.rmi.RemoteException;
import java.rmi.server.RMIClientSocketFactory;
import java.rmi.server.RMIServerSocketFactory;
import java.rmi.server.UnicastRemoteObject;

/**
 * JAVA RMI 学习：远程调用时需要传输的对象 <p>
 * 1，远程服务对象实现类写在服务端；必须继承 UnicastRemoteObject或其子类 <p>
 * 2，UnicastRemoteObject 实现了 Serializable接口，所以也需要定义 serialVersionUID <p>
 *
 * @author ME
 * @date   2020/2/24
 */
public class OrderServiceImpl extends UnicastRemoteObject implements OrderService {

    private static final long serialVersionUID = -1759110553457553411L;

    protected OrderServiceImpl() throws RemoteException {
    }

    protected OrderServiceImpl(int port) throws RemoteException {
        super(port);
    }

    protected OrderServiceImpl(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf)
        throws RemoteException {
        super(port, csf, ssf);
    }

    @Override
    public String queryOrderByUser(User user) throws RemoteException {
        System.out.println("this is server, hello: " + user.getName());
        return "hello " + user.getName();
    }
}
